package proxy

import (
	"sync"
	"time"

	"network-firewall-go/internal/types"
)

// ServerStats 服务器统计信息
type ServerStats struct {
	mu            sync.RWMutex
	connections   int
	totalRequests int64
	startTime     time.Time
}

// addConnection 添加连接计数
func (s *ServerStats) addConnection() {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.connections++
}

// removeConnection 移除连接计数
func (s *ServerStats) removeConnection() {
	s.mu.Lock()
	defer s.mu.Unlock()
	if s.connections > 0 {
		s.connections--
	}
}

// GetStatus 获取代理状态
func (s *ServerStats) GetStatus() *types.ProxyStatus {
	s.mu.RLock()
	defer s.mu.RUnlock()

	return &types.ProxyStatus{
		Running:        true,  // 这里需要从Server获取实际状态
		Port:           12300, // 这里需要从Server获取实际端口
		InterceptHTTPS: true,
		StartTime:      s.startTime.Unix(),
		Connections:    s.connections,
		Transactions:   s.totalRequests,
	}
}
